package com.win.servlet;

import com.win.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * @Author:
 * @Date: 2024/7/19 12:53
 * @Description:
 */
public class SessionDemo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 请求字符编码
        req.setCharacterEncoding("utf-8");
        // 响应字符编码
        resp.setCharacterEncoding("utf-8");
        // 将text转html
        resp.setContentType("text/html;charset=utf-8");

        HttpSession session = req.getSession();
        //获取字符
        String name = (String) session.getAttribute("name");
        resp.getWriter().write(name);

        //获取User
        User user = (User) session.getAttribute("user");
        resp.getWriter().write(String.valueOf(user));
    }
}
